package com.mflex.flexwi.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mflex.flexwi.R;
import com.mflex.flexwi.bean.WIItem;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class WIAdapter extends BaseAdapter {
    List<WIItem> items;
    Activity context;

    public WIAdapter(Activity context, List<WIItem> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        WIItem item = items.get(position);
        View view = convertView;
        view = context.getLayoutInflater().inflate(R.layout.pdf_list, null);
//        ViewHolder = new ViewHolder();
        ((TextView) view.findViewById(R.id.txtIndex)).setText(String.valueOf(position + 1));
        ((TextView) view.findViewById(R.id.txtProduct)).setText(StringUtils.equals(item.getProduct(), "anyType{}") ? StringUtils.EMPTY : item.getProduct());
//        ((TextView) view.findViewById(R.id.txtOperation)).setText(StringUtils.equals(item.getOperation(), "anyType{}") ? StringUtils.EMPTY : item.getOperation());
        ((TextView) view.findViewById(R.id.txtFileName)).setText(StringUtils.equals(item.getFileName(), "anyType{}") ? StringUtils.EMPTY : item.getFileName());
        ((TextView) view.findViewById(R.id.txtFileNo)).setText(StringUtils.equals(item.getFileNo(), "anyType{}") ? StringUtils.EMPTY : item.getFileNo());
        ((TextView) view.findViewById(R.id.txtFileType)).setText(StringUtils.equals(item.getFileType(), "anyType{}") ? StringUtils.EMPTY : item.getFileType());
        ((TextView) view.findViewById(R.id.txtFileVersion)).setText(StringUtils.equals(item.getFileVersion(), "anyType{}") ? StringUtils.EMPTY : item.getFileVersion());
        ((TextView) view.findViewById(R.id.txtEditUser)).setText(StringUtils.equals(item.getUpdatedBy(), "anyType{}") ? StringUtils.EMPTY : item.getUpdatedBy());
        ((TextView) view.findViewById(R.id.txtEditDate)).setText(StringUtils.equals(item.getUpdatedTime(), "anyType{}") ? StringUtils.EMPTY : item.getUpdatedTime());
        ((TextView) view.findViewById(R.id.txtIdentifier)).setText(StringUtils.equals(item.getIdentifier(), "anyType{}") ? StringUtils.EMPTY : item.getIdentifier());
        if (position % 2 == 0) {
            ((LinearLayout) view.findViewById(R.id.txtWIList)).setBackgroundColor(Color.rgb(221, 221, 221));
        }
        return view;
    }
}
